package xtu.www.viewinject;

import java.util.TreeMap;

import android.support.annotation.Nullable;


/**
 * Created by huilin on 2017/12/9.
 */

public class MvpModelData {
    private static TreeMap<String, Object> objectTreeMap = new TreeMap<>();

    public static @Nullable <T> T getModelImpl(String className, String packName) {
        String name = packName + "." + className + "_Mvp";
        if (objectTreeMap.containsKey(name)) {
            return (T) objectTreeMap.get(name);
        } else {
            try {
                Class<?> aClass = Class.forName(name);
                Object o = aClass.newInstance();
                if (o != null) {
                    objectTreeMap.put(name, o);
                    return (T) o;
                }
            } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
